package com.qf.controller;

import com.qf.etype.UserdetailDto;
import com.qf.pojo.Userdetail;
import com.qf.service.UserdetailService;
import com.qf.util.BaidCensorUtil;
import com.qf.util.StrUtil;
import com.qf.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/userderail")
public class UserdetailController {
    @Autowired
    private UserdetailService userdetailService;

    //修改个人信息
    @PostMapping("/update.do")
    public R updateDetail(int uid, UserdetailDto userdetailDto) {
        return userdetailService.update(uid,userdetailDto);
    }

    //查询单个人的信息
    @GetMapping("/findOne.do")
    public R findOne(int uid) {
        return userdetailService.findOne(uid);
    }

    //检验昵称是否合规
    @GetMapping("/checkNickname.do")
    public R checkNickname(String nickname) {
        if (!StrUtil.checkNoEmpty(nickname)) {
            if (nickname.length() < 12) {
                if (BaidCensorUtil.consirText(nickname)) {
                    return R.ok();
                }
            }
        }
        return R.fail("该昵称违规");
    }

    //检验签名是否合规
    @GetMapping("/checkDescription.do")
    public R checkDescription(String description) {

        if (!StrUtil.checkNoEmpty(description)) {
            if (description.length() < 12) {
                if (BaidCensorUtil.consirText(description)) {
                    return R.ok();
                }
            }
        }
        return R.fail("该签名违规");
    }
}
